package com.zhengke.controller.hubf;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.pojo.SysOrder;
import com.zhengke.pojo.SysOrderResult;
import com.zhengke.service.INoOrderService;

@Controller
@RequestMapping("noOreder")
public class INoOrderController {
	
	@Autowired
	INoOrderService iorderService;

	// 查询未完成订单的方法
	@RequestMapping("/goToNoOrder.do")
	public String gotoNoOrderLost() {
		return "/noOrderList";
	}

	@RequestMapping("/querryNoOrder.do")
	@ResponseBody
	public SysOrderResult querryNoOrder(String orderSn, String userId, String userName, String orderState, int page,
			int limit) {
		// 输出参数
		System.out.println(
				"订单的编号=>" + orderSn + "订单对应的用户id==>" + userId + "订单对应的用户的名称==>" + userName + "订单的状态==>" + orderState);
		SysOrderResult sysoOrderResult = null;
		// 将数据放入到集合中去供xml文件查询
		try {
			Map<String, Object> messageMap = new HashMap<String, Object>();
			messageMap.put("order_sn", orderSn);
			messageMap.put("user_id", userId);
			messageMap.put("user_name", userName);
			messageMap.put("order_state", orderState);
			
			// 将前台返回的两个数据的参数进行接收，然后返回，如果后面的参数设置成true的话就会自动进行返回
			PageHelper.startPage(page, limit, true);
			// 根据模糊查询的所有的订单的数据
			List<SysOrder> orderList = iorderService.querryNoOrder(messageMap);
			System.out.println(orderList);
			// 将查询到的所有的订单的结果交给PageHelper进行处理
			PageInfo<SysOrder> pageInfo = new PageInfo<SysOrder>(orderList);
			
			// 创建一个返回结果参数的实体类
			sysoOrderResult = new SysOrderResult();
			sysoOrderResult.setCode("0");
			sysoOrderResult.setMsg("");
			sysoOrderResult.setData(orderList);// 将查询的数据放到Result对象中去
			// 让paghHepler自动获取到查询订单数据的总条数
			sysoOrderResult.setCount(pageInfo.getTotal());
		} catch (Exception e) {
			e.getStackTrace();
		}
		return sysoOrderResult;
	}
	
	
	
}
